import React, { Component } from 'react';
import ReactJson from 'react-json-view'
import {ApiOfActuator} from '#/utils/actuatorApiDefine'

export default class Home extends Component {
  static displayName = 'Home';

  constructor() {
    super();
    this.state = {
      json_object: {},
    };
  }

  componentWillMount() {
    this.fetch(this.props.match.params.feature)
  }

  componentWillReceiveProps(nextProps) {
    if(this.props.match.params.feature != nextProps.match.params.feature){
      this.fetch(nextProps.match.params.feature) 
    }
  }

  fetch(feature) {
    let that = this;
    ApiOfActuator(feature).then(response => {
      that.setState({
        json_object: response
      })
    })
  }


  render() {
    return (
      <div>
        <ReactJson src={this.state.json_object} theme="monokai" />
      </div>
    );
  }
}
